home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 3.5 KB | 158 lines |
- import java.awt.Graphics;
- import java.awt.Dimension;
- import java.awt.Component;
- import java.awt.Color;
- import java.awt.Container;
-
- /**
- * Apple Worldwide Developer Technical Support
- *
- * Sample showing how to send and receive AppleEvents using JDirect 2.
- *
- * File: Divider.java
- *
- * Draws a horizontal divider of the form:
- *
- * 122222222~22222222
- * 233333333~33333333
- *
- * or a vertical divider of the form:
- *
- * 12
- * 23
- * 23
- * 23
- * 23
- * ~~
- * 23
- * 23
- * 23
- * 23
- *
- * Where each number represents a pixel:
- * 1 is R:126, G:126, B:126.
- * 2 is R:194, G:194, B:194.
- * 3 is R:242, G:242, B:242.
- *
- * @author Levi Brown
- * @author Apple Computer, Inc.
- *
- * Copyright ©1999 Apple Computer, Inc.
- * All rights reserved.
- *
- * @version 1.0
- * 4/15/1999 Shipped as 'AppleEvent Send and Receive' sample.
- *
- * You may incorporate this sample code into your applications without
- * restriction, though the sample code has been provided "AS IS" and the
- * responsibility for its operation is 100% yours. However, what you are
- * not permitted to do is to redistribute the source as "Apple Sample
- * Code" after having made changes. If you're going to re-distribute the
- * source, we require that you make it clear in the source that the code
- * was descended from Apple Sample Code, but that you've made changes.
- */
- public class Divider extends java.awt.Component
- {
- /**
- * Constructs a new horizontal Divider.
- */
- public Divider()
- {
- isHorizontal = true;
- color1 = new Color(126, 126, 126);
- color2 = new Color(194, 194, 194);
- color3 = new Color(242, 242, 242);
- }
-
-
- /**
- * Changes the orientation of the Divider between horizontal and vertical.
- * @param if true, the Divider will be horizontal,
- * if false it will be vertical.
- * @see #isHorizontal
- */
- public void setHorizontal(boolean isHorizontal)
- {
- if (this.isHorizontal != isHorizontal)
- {
- this.isHorizontal = isHorizontal;
- invalidate();
- Container parent = getParent();
- if (parent != null)
- parent.validate();
- }
- }
-
- /**
- * The orientation of the Divider
- * @return if true, the Divider is horizontal,
- * if false it is vertical.
- * @see #setHorizontal
- */
- public boolean isHorizontal()
- {
- return isHorizontal;
- }
-
- /**
- * Returns the preferred size of this component.
- * @see #getMinimumSize
- * @see LayoutManager
- */
- public Dimension getPreferredSize()
- {
- Dimension s = getSize();
-
- if (isHorizontal)
- {
- return new Dimension(s.width, 2);
- }
- else
- {
- return new Dimension(2, s.height);
- }
- }
-
- /**
- * Paints the component. This method is called when the contents
- * of the component should be painted in response to the component
- * first being shown or damage needing repair. The clip rectangle
- * in the Graphics parameter will be set to the area which needs
- * to be painted.
- * @param g the specified Graphics window
- * @see #update
- */
- public void paint(Graphics g)
- {
- super.paint(g);
-
- Dimension s = getSize();
-
- if (isHorizontal)
- {
- g.setColor(color1);
- g.drawLine(0, 0, 0, 0);
- g.setColor(color2);
- g.drawLine(1, 0, s.width, 0);
- g.drawLine(0, 1, 0, 1);
- g.setColor(color3);
- g.drawLine(1, 1, s.width, 1);
- }
- else
- {
- g.setColor(color1);
- g.drawLine(0, 0, 0, 0);
- g.setColor(color2);
- g.drawLine(0, 1, 0, s.height);
- g.drawLine(1, 0, 1, 0);
- g.setColor(color3);
- g.drawLine(1, 1, 1, s.height);
- }
- }
-
- protected boolean isHorizontal;
- protected Color color1;
- protected Color color2;
- protected Color color3;
- }
-